$(function () {
    let id = localStorage.getItem("newsId");
    getByNewsId(id);
});

function getByNewsId(id) {
    let data = myAjax('/getByNewsId', 'get', {id: id});
    data = data.list;
    // console.log(data);
    //根据id给上一页下一页赋不能点的空值
    $("#shangyitiao").html('<span>上一条：无</span>');
    $("#xiayitiao").html('<span>下一条：无</span>');
    for (let i = 0; i < data.length; i++) {
        //根据数据的id进行判断 进行不同操作
        if (data[i].id < id) {
            $("#shangyitiao").html('<span onclick="getByNewsId(' + data[i].id + ')">上一条：' + data[i].newsTitle + '</span>');
        } else if (data[i].id == id) {
            console.log("----------------");
            setNewsData(data[i]);
        } else {
            $("#xiayitiao").html('<span onclick="getByNewsId(' + data[i].id + ')">下一条：' + data[i].newsTitle + '</span>');
        }
    }
}

function setNewsData(data) {
    $("#publisher").html(data.publisher);
    $("#title").html(data.newsTitle);
    $("#biaoti").html(data.newsTitle);
    $("#releaseTime").html(data.releaseTime);
    $("#newsContent").html(data.subTitle);
    $('#concreteContent').html(data.newsContent);
    $("#subTitle").html(data.subTitle);
    // $("#browse").html(data.browse);
}

function flushThis() {
    location.replace(location)
}
